/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.testis.orm.refinedclasses;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;

import org.testis.orm.classes.T_bed_serialconnection;
import org.testis.utils.middleware.SerialConnectionDataHandler;

/**
 * 
 * @author selcuk
 */
public class SerialConnectionRefined extends TestBedItem {

    private T_bed_serialconnection m_reference;

    public SerialConnectionRefined(T_bed_serialconnection reference) {
	super();
	setReference(reference);
    }

    public int getId() {
	return m_reference.getId();
    }

    public String getName() {
	return m_reference.getName();
    }

    private void setReference(T_bed_serialconnection reference) {
	if (reference == null) {
	    throw new NullPointerException();
	}
	m_reference = reference;
    }

    @Override
    public String toString() {
	return getName();
    }

    @Override
    public String getTypeName() {
	return "SerialConnection";
    }

    public static SerialConnectionRefined[] getConnectionArray() {
	Collection coll = SerialConnectionDataHandler.newInstance()
		.getSerialConnections();
	SerialConnectionRefined[] result = new SerialConnectionRefined[coll
		.size()];
	int idx = 0;
	for (Iterator it = coll.iterator(); it.hasNext(); idx++) {
	    T_bed_serialconnection ref = (T_bed_serialconnection) it.next();
	    result[idx] = new SerialConnectionRefined(ref);
	}
	return result;
    }

    public static LinkedList<SerialConnectionRefined> getConnectionList() {
	SerialConnectionRefined[] connArray = getConnectionArray();
	LinkedList<SerialConnectionRefined> result = new LinkedList<SerialConnectionRefined>();
	for (int i = 0; i < connArray.length; i++) {
	    result.add(connArray[i]);
	}
	return result;
    }

    public static HashMap getConnectionMap() {
	SerialConnectionRefined[] connArray = getConnectionArray();
	HashMap result = new HashMap();
	for (int i = 0; i < connArray.length; i++) {
	    result.put(connArray[i].getId(), connArray[i]);
	}
	return result;
    }

    public static void main(String args[]) {
	java.awt.EventQueue.invokeLater(new Runnable() {

	    @Override
	    public void run() {
		SerialConnectionRefined[] result = SerialConnectionRefined
			.getConnectionArray();
	    }
	});
    }
}
